package com.zq.多线程设计模式.EventDriven设计模式.EDA;

import java.util.LinkedList;
import java.util.Queue;

public class EventDrivenExample {

    public static void handleEventA(Event event) {
        System.out.println(event.getMessage().toUpperCase());
    }

    public static void handleEventB(Event event) {
        System.out.println(event.getMessage().toUpperCase());
    }

    public static void main(String[] args) {

        Queue<Event> queue = new LinkedList();
        queue.add(new Event("A", "1"));
        queue.add(new Event("A", "2"));
        queue.add(new Event("B", "3"));
        queue.add(new Event("B", "4"));
        queue.add(new Event("A", "5"));
        Event event;
        while (!queue.isEmpty()) {
            event = queue.remove();
            switch (event.getType()) {
                case "A":
                    handleEventA(event);
                    break;
                case "B":
                    handleEventB(event);
                    break;
            }
        }
    }
}
